<template>
    <div class="broadAdd">
        <div class="val">
            <h2 class="tit">健康讲堂直播新增</h2>
            <!-- 直播标题 -->
            <Form ref="params" :model="params" :rules="ruleValidate" :label-width="90" label-position="left" >
                <div class = 'main'>
                    <p class="title">基本信息</p>
                    <Row class="box" :gutter="32">
                        <Col span="16">
                            <FormItem label="直播标题:" prop="title">
                                <Input v-model.trim="params.title" placeholder="请输入直播标题"  maxlength='30'></Input>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <div style="display:flex">
                                <span class="hongdian">*</span>
                                <!-- 直播封面 -->
                                <FormItem label="直播封面:">
                                    <div class="input">
                                        <div class="demo-upload-list" v-for="item in uploadList">
                                            <div v-if="item.status === 'finished'">
                                                <img :src="item.url">
                                                <div class="demo-upload-list-cover">
                                                    <Icon
                                                        type="ios-eye-outline"
                                                        @click.native="handleView(item.name)"
                                                    ></Icon>
                                                    <Icon
                                                        type="ios-trash-outline"
                                                        @click.native="handleRemove(item)"
                                                    ></Icon>
                                                </div>
                                            </div>
                                            <div v-else>
                                                <Progress
                                                    v-if="item.showProgress"
                                                    :percent="item.percentage"
                                                    hide-info
                                                ></Progress>
                                            </div>
                                        </div>
                                        <Upload
                                            v-show="uploadList.length ==0"
                                            ref="upload"
                                            :show-upload-list="false"
                                            :default-file-list="defaultList"
                                            :on-success="handleSuccess"
                                            :format="['jpg','jpeg','png']"
                                            :max-size="1024"
                                            :on-format-error="handleFormatError"
                                            :on-exceeded-size="handleMaxSize"
                                            :before-upload="handleBeforeUpload"
                                            multiple
                                            type="drag"
                                            :action="uploadUrl"
                                            :headers="fromData"
                                            :data="uploadData"
                                            style="display: inline-block;width:58px;vertical-align: middle;"
                                        >
                                            <div style="width: 58px;height:58px;line-height: 58px;">
                                                <Icon type="ios-camera" size="20"></Icon>
                                            </div>
                                        </Upload>
                                        <span class="tu">(建议尺寸：750*300px)</span>
                                        <Modal title="预览图片" v-model="visible" footer-hide>
                                            <img :src=" uploadList[0].url " v-if="visible" style="width: 100%">
                                        </Modal>
                                    </div>
                                </FormItem>
                            </div>     
                        </Col>
                        <Col span="8">
                            <!-- 开始时间 -->
                            <div class="timers">
                                <FormItem label="直播时间:" prop="startTime" >
                                    <DatePicker
                                        type="date"
                                        placeholder="选择年月日"
                                        style="width: 150px;"
                                        v-model="params.startTime"
                                        format='yyyy年MM月dd日'
                                        :options="options3"
                                        @on-change ='pickerChange'
                                    ></DatePicker>
                                    <TimePicker
                                        type="time"
                                        placeholder="选择时间"
                                        style="width: 100px;"
                                        v-model="params.startTimers"
                                        @on-change ='pickerChange'
                                        :disabled-hours="startdisabledHours"
                                        hide-disabled-options
                                        format="HH:mm"
                                    ></TimePicker>
                                </FormItem>
                            </div>  
                        </Col>
                        <Col span="8">
                            <!-- 结束时间 -->
                            <div class="timers">
                                <FormItem label="结束时间:" prop="endTime" >
                                    <DatePicker
                                        type="date"
                                        placeholder="选择年月日"
                                        style="width: 150px"
                                        v-model="params.endTime"
                                        format='yyyy年MM月dd日'
                                        :options="options4"
                                        @on-change ='endTimeLargeStart'
                                    ></DatePicker>
                                    <TimePicker
                                        type="time"
                                        placeholder="选择时间"
                                        style="width: 100px"
                                        v-model="params.endTimers"
                                        :disabled-hours="disabledHours"
                                        hide-disabled-options
                                        format="HH:mm"
                                        @on-change ='endTime'
                                    ></TimePicker>
                                </FormItem>
                            </div>
                        </Col>
                        <Col span="8">
                            <div style="display:flex">
                                <span class="hongdian">*</span>
                                <!-- 直播封面 -->
                                <FormItem label="直播列表图:">
                                    <div class="input">
                                        <div class="demo-upload-list" v-for="items in tabulatList">
                                            <div v-if="items.status === 'finished'">
                                                <img :src="items.url">
                                                <div class="demo-upload-list-cover">
                                                    <Icon
                                                        type="ios-eye-outline"
                                                        @click.native="handleViewlist(items.name)"
                                                    ></Icon>
                                                    <Icon
                                                        type="ios-trash-outline"
                                                        @click.native="handleRemovelist(items)"
                                                    ></Icon>
                                                </div>
                                            </div>
                                            <div v-else>
                                                <Progress
                                                    v-if="items.showProgress"
                                                    :percent="items.percentage"
                                                    hide-info
                                                ></Progress>
                                            </div>
                                        </div>
                                        <Upload
                                            v-show="tabulatList.length ==0"
                                            ref="listupload"
                                            :show-upload-list="false"
                                            :default-file-list="tabdefaultList"
                                            :on-success="handleSuccesslist"
                                            :format="['jpg','jpeg','png']"
                                            :max-size="1024"
                                            :on-format-error="handleFormatErrorlist"
                                            :on-exceeded-size="handleMaxSizelist"
                                            :before-upload="handleBeforeUploadlist"
                                            multiple
                                            type="drag"
                                            :action="uploadUrl"
                                            :headers="fromData"
                                            :data="uploadData"
                                            style="display: inline-block;width:58px;vertical-align: middle;"
                                        >
                                            <div style="width: 58px;height:58px;line-height: 58px;">
                                                <Icon type="ios-camera" size="20"></Icon>
                                            </div>
                                        </Upload>
                                        <span class="tu">(建议尺寸：170*170px)</span>
                                        <Modal title="预览图片" v-model="visiblelist" footer-hide>
                                            <img :src=" tabulatList[0].url " v-if="visiblelist" style="width: 100%">
                                        </Modal>
                                    </div>
                                </FormItem>
                            </div> 
                        </Col>
                        <Col span="8">
                            <!-- 直播形式 -->
                            <FormItem label="直播形式:" prop="livexs">
                                <Select v-model="params.livexs" style="width:160px">
                                    <Option
                                        v-for="item in livexsList"
                                        :value="item.id"
                                        :key="item.id"
                                        style='text-align:center;'
                                    >{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <!-- 直播类型 -->
                            <FormItem label="直播类型:" prop="liveType">
                                <Select v-model="params.liveType" style="width:160px">
                                    <Option
                                        v-for="item in liveTypeList"
                                        :value="item.id"
                                        :key="item.id"
                                        style='text-align:center;'
                                    >{{ item.name }}</Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <!-- 课堂类型 -->
                            <FormItem label="课堂类型:" prop="type">
                                <Select v-model="params.type" style="width:160px">
                                    <Option
                                        v-for="item in columnList"
                                        :value="item.id"
                                        :key="item.id"
                                        style='text-align:center;'
                                    >{{ item.columnName }}</Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <!-- 是否付费 -->
                            <div class="spacing suojin">
                                <span style="margin-right:10px;">支付类型:</span>
                                <RadioGroup v-model="liveMoneyTypes" @on-change='radioChange'>
                                    <Radio label="0">免费</Radio>
                                    <Radio label="1">付费</Radio>
                                </RadioGroup>
                            </div>
                        </Col>
                        <Col span="8"> 
                            <!-- 原始价格 -->
                            <FormItem label="原始价格:" prop="oldPrice" v-if="liveMoneyTypes==1">
                                <div class="spacing" >
                                    <!-- <InputNumber
                                        :max="9999"
                                        :min="1"
                                        v-model="params.oldPrice"
                                        style="width:150px;"
                                        @on-change='computedMaxPrice'
                                        @on-blur="oldPriceChange(params.oldPrice, 1)"
                                    ></InputNumber> -->
                                    <input min="0" max="9999" @on-change="computedMaxPrice" @on-blur="oldPriceChange(params.oldPrice, 1)" v-model="params.oldPrice" type="number" @input="srInput" class="inputnumber" />
                                </div>
                            </FormItem> 
                        </Col>
                        <Col span="8"> 
                            <!-- 折后价格 -->
                            <div class="spacing" v-show="liveMoneyTypes==1">
                                <span style="margin-right:10px;">折后价格:</span>                            
                                <!-- <InputNumber
                                    :max="oldMoney"
                                    :min="0"
                                    v-model="params.newPrice"
                                    style="width:150px;"
                                    @on-blur="oldPriceChange(params.newPrice, 2)"
                                ></InputNumber> -->
                                <input min="0" max="oldMoney" @on-blur="oldPriceChange(params.newPrice, 2)" v-model="params.newPrice" type="number"  @input="dissrInput" class="inputnumber" />
                                <span class="tu">(折后价格需小于原始价格)</span>
                            </div>
                        </Col>
                    </Row>
                </div>
                <div class = 'main'>
                    <p class="title">主讲人信息</p>
                    <Row class="box" :gutter="32">
                        <Col span="23" style="margin-bottom:10px">
                            <Button type="primary" @click="modalStatusclick" >
                                <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>添加医生
                            </Button>
                            <small style="color:#ff9966">（备注：可选择平台医生，将会带出医生详细信息。）</small>  
                        </Col>
                        <Col span="8">                        
                            <div class="spacing">
                                <span style="margin-right:10px;"><i style="color:red;margin-right:5px">*</i>直播医生:</span>  
                                <span>{{doctorName}}</span>
                                <!-- <Input v-model="doctorName" placeholder="请输入主讲人姓名" clearable maxlength='30' readonly style="width:80%"
                                disabled = 'true'
                                /> -->
                            </div>
                        </Col> 
                        <Col span="8">  
                            <div class="spacing">
                                <span style="margin-right:10px;"><i style="color:red;margin-right:5px">*</i>所属机构:</span>                            <span>{{doctorhospitaName}}</span> 
                                <!-- <Input v-model="doctorhospitaName" placeholder="请输入主讲人姓名" clearable maxlength='30' readonly style="width:80%"/> -->
                            </div>
                        </Col>     
                        <Col span="8">  
                            <div class="spacing">
                                <span style="margin-right:10px;"><i style="color:red;margin-right:5px">*</i>职业职称:</span>                            <span>{{doctorTitle}}</span> 
                                <!-- <Input v-model="doctorTitle" placeholder="请输入职业职称" clearable maxlength='30' readonly style="width:80%"/> -->
                            </div>
                        </Col>  
                        <Col span="8" v-if="doctortype==1"> 
                            <div class="spacing">
                                <span style="margin-right:10px;"><i style="color:red;margin-right:5px">*</i>所属科室:</span>                            <span>{{deptName}}</span> 
                                <!-- <Input v-model="deptName" placeholder="请输入所属科室" clearable maxlength='30' readonly style="width:80%"/> -->
                            </div> 
                        </Col>          
                        <Col span="23">  
                            <div class="spacing">
                                <span style="margin-right:10px;min-width:60px"><i style="color:red;margin-right:5px"></i>个人简介:</span>
                                <span>{{introduction}}</span> 
                                <!-- <Input v-model="introduction" placeholder="请输入个人简介" clearable maxlength='30'  style="width:80%"/> -->
                                <!-- readonly： Input不可输入,只读 -->
                            </div> 
                        </Col>    
                        <Col span="8">  
                        </Col>  
                    </Row>
                </div>
                <!-- 模态框 -->
                <Modal title="添加主播医生" width="1000" footer-hide v-model="modalStatus" :styles="{top: '80px'}">
                    <div>
                        <!-- 查询条件 -->
                        <Row>
                            <Col span="24">
                            <fourLevelLinkage
                                @changeProvince="changeProvince"
                                @changeCity="changeCity"
                                @changeArea="changeArea"
                                @changeHospital="changeHospital"
                                :province="province"
                                :city="city"
                                :area="area"
                                :hospital="hospital"
                            ></fourLevelLinkage>
                                <Input
                                    v-model.trim="search"
                                    placeholder="搜索主播医生"
                                    style="width: 200px"
                                />
                                <Button type="primary" icon="ios-search" @click='searchdoctor'></Button>
                            </Col>
                        </Row>
                        <!-- 显示列表 -->
                        <Row
                            type="flex"
                            justify="space-around"
                            class="code-row-bg"
                            style="margin-top:20px;"
                        >
                            <Col span="24">
                                <Table stripe :columns="columns" :data="data1"></Table>
                                <div class="page">
                                    <Page :total="count" :current='pageNo' :page-size="pageSize" show-total show-elevator @on-change="loading"/>
                                </div>
                            </Col>
                        </Row>
                    </div>
                </Modal>
                <!-- 讲堂介绍 -->
                <div class = 'main'>
                    <p class="title">课堂介绍</p>
                    <div class="vueeditor spacing">
                        <Input
                            v-model="params.content"
                            type="textarea"
                            placeholder="请简要描述本次直播课堂介绍"
                            :rows="4"
                            style="margin: 0 40px;"
                            maxlength="500"
                        />
                    </div>
                </div>
            </Form>
        </div>
        <!-- 创建/取消 -->
        <div style="margin:20px 0;width: 100%;text-align:center">
            <Button type="primary" @click="handleSubmit('params')" :disabled='disabledSave' class="btn">
                <Icon type="ios-checkmark" style="margin-right: 5px" />保存
            </Button>
            <Button @click="back" class="btn">
                <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
            </Button>
        </div>
    </div>
</template>
<script>
import { DatePicker, TimePicker } from "view-design";
import api from "@/api/commonApi";
import fourLevelLinkage from "@/components/fourLevelLinkage";
import code from "@/configs/base.js";
export default {
    components: {
        DatePicker,
        TimePicker,
        fourLevelLinkage
    },
    data() {
        return {
            province: null,
            city: null,
            area: null,
            hospital: null,

            // 医生查询数据
            search: "",
            // 直播价格
            liveMoneyTypes: "0",
            params: {
                // 标题
                title: "",
                // 开始时间
                startTime: "",
                startTimers: "",
                // 结束时间
                endTime: "",
                endTimers: "",
                // 直播形式
                livexs:"",
                // 直播类型
                liveType:"",
                // 课堂类型
                type: "",
                // 医生
                doctor: "",
                // 价格
                oldPrice: 0,
                newPrice: '',
                // 力度
                Intensity: "",
                // 介绍
                content: "",
                // 库存
                stock:""
            },
            ruleValidate: {
                title: [
                    {
                        // 是否校验
                        required: true,
                        // 提示文字
                        message: "请输入直播标题",
                        // 触发事件
                        trigger: "blur"
                    }
                ],
                startTime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择开始日期",
                        trigger: "change"
                    }
                ],
                startTimers: [
                    {
                        required: true,
                        type: "string",
                        message: "请选择开始时间",
                        trigger: "change"
                    }
                ],
                endTime: [
                    {
                        required: true,
                        type: "date",
                        message: "请选择结束日期",
                        trigger: "change"
                    }
                ],
                endTimers: [
                    {
                        required: true,
                        type: "string",
                        message: "请选择结束时间",
                        trigger: "change"
                    }
                ],
                type: [
                    {
                        required: true,
                        message: "请选择课堂类型",
                        trigger: "change"
                    }
                ],
                liveType: [
                    {
                        required: true,
                        message: "请选择直播类型",
                        trigger: "change"
                    }
                ],
                livexs: [
                    {
                        required: true,
                        message: "请选择直播形式",
                        trigger: "change"
                    }
                ],
                oldPrice: [
                    {
                        // 是否校验
                        required: true,
                        // 提示文字
                        message: "请输入原始价格",
                        // 触发事件
                        trigger: "blur"
                    }
                ],
            },
            columnList: [],
            // 医生弹出框
            modalStatus: false,
            // 添加医生权限管理数据
            data1: [],
            // 页码
            pageNo: 1,
            // 页数
            pageSize: 10,
            // 添加医生总数
            count:10,
            // 医生表头数据
            columns: [
                {
                    title: "排序",
                    key: "sum",
                    align: "center",
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    title: "姓名",
                    key: "doctorName",
                    align: "center",
                },
                {
                    title: "所在医院",
                    key: "hospitalName",
                    align: "center",
                    width: 240
                },
                {
                    title: "科室",
                    key: "deptName",
                    align: "center"
                },
                {
                    title: "职称",
                    key: "titleName",
                    align: "center"
                },
                {
                    title: "设置",
                    key: "operate",
                    align: "center",
                    // width: 60,
                    render: (h, params) => {
                        let row = params.row
                        let doctorId = row.doctorId
                        let hospitalId = row.hospitalId
                        let doctorName = row.doctorName
                        let titleName = row.titleName
                        let deptName = row.deptName
                        let doctortype = row.type
                        let doctorhospitaName = row.hospitalName
                        let personalIntroduction = row.personalIntroduction
                        return h(
                            "a",
                            {
                                attrs: {
                                    href: "javascript:void(0);"
                                },
                                on: {
                                    click: () => {
                                        this.doctorhospitaid = hospitalId
                                        this.doctorId = doctorId
                                        this.doctorName = doctorName
                                        this.doctorTitle = titleName
                                        this.deptName = deptName
                                        this.doctortype = doctortype
                                        this.doctorhospitaName = doctorhospitaName
                                        this.introduction = personalIntroduction
                                        this.modalStatus = false
                                    }
                                }
                            },
                            "添加"
                        );
                    }
                }
            ],
            doctorhospitaid:"",
            doctorId:"",
            doctorName:"",
            doctorhospitaName:"",
            //职业职称
            doctorTitle: "",
            //所属科室
            deptName: "",
            doctortype:null,
            //个人简介
            introduction: "",
            defaultList: [],
            visible: false,
            visiblelist: false,
            uploadList: [],
            uploadModal: true,
            urlCode: '{"urlCode":"' + code.urlCode.liveStart + '"}',
            uploadData: { json: '{"urlCode":"' + code.urlCode.onDemand + '"}' },
            activeUploadId: "5c2bf345-b973-4ffd-a52e-87bb9c1d2b72",
            uploadUrl: api.fileAll,
            tabulatList: [],
            tabdefaultList: [],
            images: "",
            listimages: "",

            // 直播类型
            liveTypeList: [
                {
                    id:"0",
                    name:"医师讲堂"
                },
                // {
                //     id:"1",
                //     name:"医学讲堂"
                // }
            ],
            // 直播形式
            livexsList:[
                {
                    id:"2",
                    name:"视频直播"
                },
            ],
            // 直播对象
            liveObjList:[
                {
                    id:"0",
                    name:"患者"
                },
                {
                    id:"1",
                    name:"医生"
                }
            ],
            options3: {
                disabledDate (date) {
                    return date && date.valueOf() < Date.now() - 86400000;
                }
            },
            options4: {
                disabledDate (date) {
                    return date && date.valueOf() < Date.now() - 86400000;
                }
            },
            disabledHours:[],
            startdisabledHours:[],
            // 折后价格最大限制
            oldMoney:0,
            disabledSave: false
        };
    },
    created() {
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/indexpublicOperation/liveMant/list",
                title: "健康讲堂"
            }
        ];
        this.$emit("changeBreadList", breadList);
    },
    mounted() {
        this.uploadList = this.$refs.upload.fileList;
        this.tabulatList = this.$refs.listupload.fileList;
        // 加载课堂类型
        this.columnDate();
        // 禁用已过期时间
        this.getCurrentTimeDisabled();
    },
    methods: {
        changeProvince(val) {
            this.province = val;
        },
        changeCity(val) {
            this.city = val;
        },
        changeArea(val) {
            this.area = val;
        },
        changeHospital(val) {
            this.hospital = val;
        },
        srInput(e) {
            this.params.oldPrice = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || null;
            if(e.target.value>9999.99)this.params.oldPrice=9999.99 
        },
        dissrInput(e) {
            this.params.newPrice = e.target.value.match(/^\d*(\.?\d{0,2})/g)[0] || null;
            if(e.target.value>9999.99)this.params.newPrice=9999.99
        },
        // 当付费状态改变时清除原始价格与折后价格
        radioChange (val) {
            // 原始价格
            this.params.oldPrice = 0;
            // 折后价格
            this.params.newPrice = 0;
        },
        oldPriceChange(val, type){
            if(val){
                val = "'"+val+"'"
                val = val.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
                val = val.replace(/^\./g,""); //验证第一个字符是数字
                val = val.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
                val = val.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
                val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
                if(val.indexOf(".") >0 && val.indexOf("0")>2){
                    val = parseFloat(val)
                }
                if(val.indexOf(".") >0 && val.lastIndexOf("0")>2){
                    val = parseFloat(val)
                }
                if(val.indexOf(".") <=0 && val!=""){
                    val = parseFloat(val)
                }
            }
            if(type == 1){
                this.params.oldPrice = val;
            }else if(type == 2){
                this.params.newPrice = val
            }
            return val;
        },
        // 折后价格不得大于原始价格
        computedMaxPrice (val) {
            this.oldMoney = val
        },
        // 获取当前时间禁用选择当前时间以前的时间
        getCurrentTimeDisabled(){
            this.startdisabledHours = []
            this.disabledHours = []
            let currentTime = new Date();
            // 当前时间
            let hours = currentTime.getHours();
            // 当前日期
            let currentday = currentTime.getDate();
            for(let i=0;i<hours;i++) {
                this.startdisabledHours.push(i)
                this.disabledHours.push(i)
            }
        },
        //  直播创建
        handleSubmit(name) {
            this.disabledSave = true
            if (!this.uploadList.length) { 
                this.disabledSave = false
                return this.$Message.error("请上传直播封面")
            }
            if (!this.tabulatList.length) { 
                this.disabledSave = false
                return this.$Message.error("请上传直播列表图")
            }
            if (!this.doctorId || !this.doctorName) {               
                this.disabledSave = false
                return this.$Message.error("请选择主播医生")
            }
            if (!this.doctorhospitaName) {               
                this.disabledSave = false
                return this.$Message.error("请选择主播医生所属机构")
            }
            if (!this.doctorTitle) {               
                this.disabledSave = false
                return this.$Message.error("请选择主播医生职业职称")
            }
            // if (!this.introduction) {               
            //     this.disabledSave = false
            //     return this.$Message.error("请输入个人简介")
            // }
            if(!this.params.startTimers) {              
                this.disabledSave = false
                return this.$Message.error("请选择具体开始时间")
            }
            if(!this.params.endTimers) {                
                this.disabledSave = false
                return this.$Message.error("请选择具体结束时间")
            } 
            // 折后价格与原始价格
            if ( this.liveMoneyTypes==1 &&
                (Number(this.params.oldPrice) <
                    Number(this.params.newPrice))
            ) {
                this.$Message.error("折后价格应小于原始价格");
                this.disabledSave = false
                return "";
            } else if(this.liveMoneyTypes==1 && (!Boolean(this.params.oldPrice) ||
                !Boolean(this.params.newPrice))) {
                    this.$Message.error("请检查原始价格与折后价格是否填写完整");
                this.disabledSave = false
                return "";
            }
            this.$refs[name].validate(valid => {
                if (valid) {
                    let params = {
                        // 结束时间
                        aboutEndTime: this.getData(this.params.endTime) +' '+this.params.endTimers,
                        // 折后价格
                        discountPrice: this.params.newPrice,
                        // 医生ID
                        doctorId: this.doctorId,
                        doctorName:this.doctorName,
                        //职业职称
                        doctorTitle: this.doctorTitle,
                        //所属科室
                        doctorDept: this.deptName,
                        //个人简介
                        doctorIntroduce: this.introduction,
                        // 推广力度
                        fictitiousNum: this.params.Intensity,
                        //图片
                        headImg: this.images,
                        listImg: this.listimages,
                        // 医院ID
                        hospitalId: this.doctorhospitaid,
                        hospitalName: this.doctorhospitaName,
                        // 是否付费
                        icharge: this.liveMoneyTypes,
                        // 介绍
                        classIntroduction: this.params.content,
                        // 直播形式
                        liveForm: this.params.livexs,
                        // 开始时间
                        aboutStartTime:this.getData(this.params.startTime) +' '+this.params.startTimers,
                        // 直播类型
                        liveType: this.params.liveType,
                        // 原始价格
                        originalPrice:this.params.oldPrice,
                        // 标题
                        title: this.params.title,
                        // 课堂类型
                        columnId: this.params.type,
                        playStatus:"1",
                        // 库存
                        stock : this.params.stock,
                        ilive : 1,
                    }
                    if (params.icharge == 0) {
                        params.discountPrice = 0;
                        params.originalPrice = 0;
                    }
                    this.columnList.forEach( i => {
                        if(this.params.type == i.id){
                            params.columnName = i.columnName
                        }
                    })
                    this.$axios.post(api.insertLecture,params).then(res =>{
                        if (res.data.success) {
                            this.$Message.success("添加成功!")
                            setTimeout(()=>{
                                this.disabledSave = false
                                let query = this.$route.query;
                                this.functionJS.queryNavgationTo(
                                    this,
                                    "/index/publicOperation/liveMant/list",
                                    query
                                );
                            },1000)                          
                        } else {
                            this.disabledSave = false
                        }
                    }).catch(err => {
                        console.log(err);
                        this.disabledSave = false
                    });                   
                } else {
                    this.$Message.error("请完整填写必填项!");
                    this.disabledSave = false
                }
            });
        },
        // 模态框显示
        modalStatusclick() {
            this.modalStatus = true;
            this.province = ''
            this.city = ''
            this.area = ''
            this.hospital = ''
            this.pageNo = 1
            this.doctorList()
        },
        searchdoctor() {
            this.pageNo = 1
            this.doctorList()
        },
        // 查询医生权限管理
        doctorList(){
            this.$axios
                .post(api.doctorAuthlist, {
                    searchKey: this.search,
                    pageNo: this.pageNo,
                    pageSize: this.pageSize,
                    provinceCode: this.province,
                    cityCode: this.city,
                    areaCode: this.area,
                    hospitalId: this.hospital,
                })
                .then(resp => {
                    if (resp.data.success) {
                        let ret = resp.data.object.records;
                        if(ret){
                            ret.forEach((item,index) =>{
                                item.sum = this.addZeros(index)
                            })
                            this.count = resp.data.object.total;
                            this.data1 = ret;
                        } else {
                            this.data1 = []
                        }                       
                    } else {
                        this.$Message.error("不允许访问");
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        endTime() {
            if(!this.params.startTimers) {
                this.params.endTimers = ''
                this.$Message.error("请先完善直播时间")
                return
            }
        },
        // 结束日期不能小于开始日期
        endTimeLargeStart(){
            if(!this.params.startTime) {
                this.params.endTime = ''
                this.$Message.error("请先完善直播日期")
                return
            }
            // 开始时间
            let startTime = new Date(this.params.startTime);
            let startDay = startTime.getDate();
            let startMonth = startTime.getMonth() + 1;

            // 结束时间
            let endTime = new Date(this.params.endTime);
            let endDay = endTime.getDate();
            let endMonth = endTime.getMonth() + 1;
            if(startMonth == endMonth){
                if(endDay < startDay) {
                    this.$Message.error("请选择开始时间之后的日期")
                    this.params.endTime = ''
                }
            }
            this.pickerChange();
        },
        // 通过开始时间限制结束时间
        pickerChange (val){
            this.startdisabledHours = []
            this.disabledHours = []
            let currentTime = new Date();
            // 当前时间
            let hours = currentTime.getHours();
            // 当前日期
            let currentday = currentTime.getDate();

            let selectTime = new Date(this.params.startTime);
            let selectDay = selectTime.getDate();
            if(Number(currentday) == Number(selectDay)) {
                this.getCurrentTimeDisabled();
            } else {
                this.startdisabledHours = []
            }
            let disTime = this.params.startTimers.split(":")[0]
            this.disabledHours = []
            if(this.getData(this.params.startTime) == this.getData(this.params.endTime)) {
                for(let i=0;i <= disTime;i++){
                    this.disabledHours.push(i)
                }
            }
            // this.params.endTimers
        },
        // 返回
        back() {
            let query = this.$route.query;
            this.functionJS.queryNavgationTo(
                this,
                "/index/publicOperation/liveMant/list",
                query
            );
        },
        // 加载栏目列表
        columnDate() {
            this.$axios.post(api.findLectureColumnList,{}).then(resp => {
                if (resp.data.success) {
                    let ret = resp.data.object;
                    ret.forEach(item => {
                        item.id = String(item.id)
                    })
                    this.columnList = ret;
                } else {
                    this.$Message.error("请求失败,请稍候重试");
                }
            });
        },
        // 页码改变
        loading(index) {
            this.pageNo = index;
            this.doctorList()
        },
        // 转换日期格式 
        getData(data){
            let datas = new Date(data)
            var curr_date = datas.getDate();
            var curr_month = datas.getMonth() + 1; 
            var curr_year = datas.getFullYear();
            function add(num){
                if(Number(num)<10) {
                    return '0' + num
                }
                return num
            }
            return curr_year + "-" + add(curr_month)+'-' + add(curr_date)
        },
        handleView(name) {
            this.imgName = name;
            this.visible = true;
        },
        handleRemove(file) {
            const fileList = this.$refs.upload.fileList;
            this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
            if(this.images){
                this.images = ''
            }
        },
        handleSuccess(res, file) {
            res = this.uploadFileDecrypt(res);
            file.url = this.fileBaseUrl + res.object[0].fileName;
            this.images = JSON.stringify(res.object[0]);
            file.name = res.object[0].fileName;
        },
        handleFormatError(file) {
            this.$Notice.warning({
                title: "格式错误",
                desc: "文件 " + file.name + " 上传失败,请重试"
            });
        },
        handleMaxSize(file) {
            this.$Notice.warning({
                title: "文件过大",
                desc: "文件"+ file.name +"过大，文件最大限制为1024KB"
            });
        },
        handleBeforeUpload(file) {
            const check = this.uploadList.length < 1;
            if (!check) {
                this.$Message.info("只能上传一张图片");
            }
            return check;
        },
        handleViewlist(name) {
            this.imgName = name;
            this.visiblelist = true;
        },
        handleRemovelist(file) {
            const fileList = this.$refs.listupload.fileList;
            this.$refs.listupload.fileList.splice(fileList.indexOf(file), 1);
            if(this.listimages){
                this.listimages = ''
            }
        },
        handleSuccesslist(res, file) {
            res = this.uploadFileDecrypt(res);
            file.url = this.fileBaseUrl + res.object[0].fileName;
            this.listimages = JSON.stringify(res.object[0]);
            file.name = res.object[0].fileName;
        },
        handleFormatErrorlist(file) {
            this.$Notice.warning({
                title: "格式错误",
                desc: "文件 " + file.name + " 上传失败,请重试"
            });
        },
        handleMaxSizelist(file) {
            this.$Notice.warning({
                title: "文件过大",
                desc: "文件"+ file.name +"过大，文件最大限制为1024KB"
            });
        },
        handleBeforeUploadlist(file) {
            const check = this.tabulatList.length < 1;
            if (!check) {
                this.$Message.info("只能上传一张图片");
            }
            return check;
        }
    }
};
</script>
<style lang="less" scoped>
.demo-upload-list {
    display: inline-block;
    width: 60px;
    height: 60px;
    text-align: center;
    line-height: 60px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    margin-right: 4px;
}
.demo-upload-list img {
    width: 100%;
    height: 100%;
}
.demo-upload-list-cover {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
    display: block;
}
.demo-upload-list-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
}
.broadAdd {
    width: calc(100%);
    padding: 10px 0px;
    margin: 0 auto;
    background: #fff;
    font-size: 12px;
    .val {
        h1,h2 {
            font-weight:bold;
        }
        .spacing {
            margin: 6px 10px;
            display: flex;
        }
        .suojin {
            margin-left: 16px;
        }
        .createdTitle {
            border-bottom: 1px solid #f2f2f2;
            margin-bottom: 20px;
        }
    }
    .main_imgs {
        display: flex;
        flex-direction: row;
        align-items: center;
        .main_title_info {
            min-width: 100px;
        }
    }
    .vueeditor {
        display: flex;
        flex-direction: row;
        align-items: center;
        div {
            min-width: 600px;
        }
    }
    .tit {
        margin:10px 0;
        font-weight:bold;
        text-align:center;
    }
    .main{
        width: 97%;
        display: flex;
        flex-direction: column;
        margin: 10px auto;
        border: 1px solid #f0f0f0;
        box-shadow: 0 4px 3px #ebedf8;
        border-radius: 5px;
        margin-bottom: 20px;
        padding-bottom: 20px;
        .title {
            font-size: 20px;
            padding-left: 15px;
            margin-bottom: 20px;
            color: #333;
            height: 40px;
            line-height: 40px;
            background: #ebedf8;         
        }
        .box{
            padding: 0 30px;
        }
        .hongdian {
            color: red;
            font-size: 18px;
            margin-top: 5px;
            margin-right: 5px;
        }
        .tu {
            color: #ff9966;
            margin-left: 15px;
        }
        .inputnumber {
            width: 150px;
            height: 30px;
            background: #fff;
            border: none;
            outline: none;
            text-indent: 10px;
            line-height: 30px;
            border: 1px solid #ddd;
            border-radius: 4px;
            color: #666;
        }
        .inputnumber:focus{
            border-color:#5362e1
        }
    }
    .btn {
        width: 75px;
        height: 35px;
    }
}
.page{
    text-align: center;
    margin: 20px 0;
}
.timers {
    display: flex;
}
</style>
